
<extend name="Public:base"/>
<block name="body">

	<style type="text/css">
		#body {
			width: 95%;
			background: white;
			border-radius: 10px;
			margin: 2.5%;
			position: relative;
		}

		.add_button {
			margin: 20px 30px;
			height: 40px;
			width: 150px;
		}
		.top_input_button{
			width: 300px;
			height: 42px;
		}
		.btn-default{
			color: #fff;
			background-image: none;
			background-color: rgba(255,150,47,1);
			border: none;
		}
		.btn-default:focus, .btn-default:hover{
			color: #fff;
			background-image: none;
			border: none;
			background-color: rgba(255,150,47,1);
		}
		tr>td>span{
			margin: 5px;
			color: #00aaee;
		}
		thead>tr>th{
			text-align: center;
		}
		#data_tr>td{
			text-align: center;
		}
		.inline{margin-left: 10px;}
	</style>
	<h2 style="color: #333333;margin: 50px"><b>文章列表</b></h2>
	<div id="body">
		<form class="form-inline" action="" method="get">
			<label class="inline">关键词:</label>
			<input type="text" name="keyword" class="form-control top_input_button" value="{$keyword}" placeholder="请输入文章标题或编号" aria-describedby="sizing-addon1">
			<label class="inline">类目:</label>
			<select class="form-control top_input_button" name="category_id">
				<option value="0">全部</option>
				<volist name="categories" id="vo">
					<option <eq name="vo.id" value="$category_id">selected</eq> value="{$vo.id}">{$vo.name}</option>
				</volist>
			</select>
			<label class="inline">状态:</label>
			<select class="form-control top_input_button" name="status">
				<option value="0">全部</option>
				<option <eq name="status" value="1">selected</eq> value="1">已发布</option>
				<option <eq name="status" value="2">selected</eq> value="2">未发布</option>
			</select>
			<label class="inline">发布时间:</label>
			<input type="text" name="start_time" class="form-control top_input_button" id="start_time" value="{$start_time|default=''}" data-date-format="yyyy-mm-dd hh:ii"> -
			<input type="text" name="end_time" class="form-control top_input_button" id="end_time" value="{$end_time|default=''}" data-date-format="yyyy-mm-dd hh:ii">
			<button type="submit" class="btn btn-default  add_button" style="width: 60px">搜索</button>
		</form>
		<a href="{:U('add')}"><button type="button" class="btn btn-default add_button ">新增文章</button></a>
		<div class="row" style="margin-left: 15px;width: 97%">
			<div class="col-xs-12">
				<table class="table table-striped table-bordered">
					<thead>
					<tr>
						<th>文章编号</th>
						<th>文章标题</th>
						<th>类目</th>
						<th>发布时间</th>
						<th>分享人数</th>
						<th>阅读人数</th>
						<th>状态</th>
						<th>数据统计</th>
						<th>操作</th>
					</tr>
					</thead>
					<tbody>
					<volist name="list" id="vo">
						<tr id="data_tr" style="overflow: hidden">
							<td>{$vo.number}</td>
							<td>{$vo.title}</td>
							<td>{$vo.category_name}</td>
							<td>{$vo.create_time|date="Y-m-d H:i",###}</td>
							<td>{$vo.share_num|default=0}</td>
							<td>{$vo.read_num|default=0}</td>
							<td>
								<eq name="vo.status" value="1">已发布<else/>未发布</eq>
							</td>
							<td><span onclick="group_table('{$vo.id}','sta')">统计 </span></td>
							<td>
								<span onclick="group_table('{$vo.id}','edit')">编辑</span>
								<span onclick="group_table('{$vo.id}','select')">查看二维码 </span>
								<eq name="vo.status" value="1">
									<span onclick="group_table('{$vo.id}','unpush')">取消发布</span>
									<else/>
									<span onclick="group_table('{$vo.id}','push')">发布</span>
								</eq>
							</td>
						</tr>
					</volist>
					</tbody>
				</table>
				{$page}
				<!-- PAGE CONTENT ENDS -->
			</div><!-- /.col -->
		</div>

	</div>

	<script>
        $('#start_time').datetimepicker({
            format: "yyyy-mm-dd hh:ii",
            autoclose: true,
            todayBtn: true,
            pickerPosition: "bottom-left"
        });
        $('#end_time').datetimepicker({
            format: "yyyy-mm-dd hh:ii",
            autoclose: true,
            todayBtn: true,
            pickerPosition: "bottom-left"
        });
        function group_table(id,event){
            if(event === 'edit'){
                window.location.href='{:U("edit")}?id='+id;
            }else if(event === 'auth'){
                window.location.href='{:U("Dxadmin/OneCode/index")}?id='+id;
            }else if(event === 'sta'){
                window.location.href = '{:U("Dxadmin/Statistics/index")}?id='+id+'&type=1&auth=1';
            }else if(event === 'select'){
                $.post(
                    'one',
                    {id:id},
                    function (res) {
                        console.log(res);
                        bootbox.alert({
                            title:"查看二维码",
                            message : "<p><h2 style='text-align: center'>"+res.name+"</h2></p>" +
                            "<div style='width: 300px;height:300px;margin:auto;'><img id='downImg' src='"+res.img+"' width='100%' height='100%'></div>" +
                            "<p style='text-align: center' onclick='downloadCode()'><span style='font-size: 30px;color: #ff9a36' class='glyphicon glyphicon-save' aria-hidden='true'></span></p>" +
                            "<p style='margin-top: 20px;font-size: 12px;text-align: center'>链接:" +
                            "<span>https://{$url.url}?id="+id+"&type="+res.type+"</span>" +
                            "<input type='text' id='copy_url' readonly value='https://{$url.url}?id="+id+"&type="+res.type+"' style='width: 1px;height: 1px;border: solid white 0;'>" +
                            "<span style='color:#397DE9' onclick='copyText()'> 点击复制</span>" +
                            "</p>",

                        });
                    }
                );
            }else if (event === 'push') {
                $.post('push',{type:'yes',id:id},function (res) {
                    if(res.status){
                        bootbox.alert({
                            title:'系统提示',
                            message:res.info
                        });
                        setTimeout(function () {
                            window.location.reload();
                        },2000)
                    }else {
                        bootbox.alert({
                            title:'系统提示',
                            message:res.info
                        })
                    }
                })
            } else if (event === 'unpush') {
                $.post('push',{type:'no',id:id},function (res) {
                    if(res.status){
                        bootbox.alert({
                            title:'系统提示',
                            message:res.info
                        });
                        setTimeout(function () {
                            window.location.reload();
                        },2000)
                    }else {
                        bootbox.alert({
                            title:'系统提示',
                            message:res.info
                        })
                    }
                })
            }
        }
        function copyText() {
            url=document.getElementById("copy_url");
            url.select(); // 选择对象
            document.execCommand("Copy"); // 执行浏览器复制命令
            bootbox.alert("复制成功", function () {
                var strResult = "";
            });
        }
        function downloadCode() {
            var img = $('#downImg').attr("src");
            window.location.href='{:U("Dxadmin/WechatCode/url")}?url='+img
        }
	</script>
</block>